﻿using System;
using TrafficArchives.Utilities;

namespace TrafficArchives
{
    public partial class Left : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Initilize();
            }
        }

        private void Initilize()
        {
            if (LoginUser.Current.IsSupperAdmin)
            {
                return;
            }
            var menuString = LoginUser.Current.MenuString;

            // 添加信誉档案。
            if (menuString.IndexOf("AddArchives.aspx", StringComparison.Ordinal) == -1)
            {
                MenuAddArchives.Visible = false;
            }
            // 信誉档案处理。
            if (menuString.IndexOf("ArchivesProcess.aspx", StringComparison.Ordinal) == -1)
            {
                MenuProcessArchives.Visible = false;
            }
            // 信誉档案查询。
            if (menuString.IndexOf("SimpleArchivesView.aspx", StringComparison.Ordinal) == -1)
            {
                MenuSimpleQueryArchives.Visible = false;
            }
            if (menuString.IndexOf("PlexArchivesView.aspx", StringComparison.Ordinal) == -1)
            {
                MenuPlexQueryArchives.Visible = false;
            }
            MenuQueryArchives.Visible = MenuSimpleQueryArchives.Visible || MenuPlexQueryArchives.Visible;
            
            // 信誉台账查询。
            if (menuString.IndexOf("ScoreBook.aspx", StringComparison.Ordinal) == -1)
            {
                MenuScoreBook.Visible = false;
            }
            if (menuString.IndexOf("AccidentBook.aspx", StringComparison.Ordinal) == -1)
            {
                MenuAccidentBook.Visible = false;
            }
            if (menuString.IndexOf("IllegalBook.aspx", StringComparison.Ordinal) == -1)
            {
                MenuIllegalBook.Visible = false;
            }
            MenuAccidentBook.Visible = MenuScoreBook.Visible || MenuAccidentBook.Visible || MenuIllegalBook.Visible;

            //拥有车辆查询
            if (menuString.IndexOf("CarsView.aspx", StringComparison.Ordinal) == -1)
            {
                MenuQueryCarRoot.Visible = MenuQueryCar.Visible = false;
            }

            // 安全教育
            if (menuString.IndexOf("SafeEducateAdd.aspx", StringComparison.Ordinal) == -1)
            {
                MenuAddSafeEducate.Visible = false;
            }
            if (menuString.IndexOf("SafeEducateProcess.aspx", StringComparison.Ordinal) == -1)
            {
                MenuProcessSafeEducate.Visible = false;
            }
            if (menuString.IndexOf("SafeEducateView.aspx", StringComparison.Ordinal) == -1)
            {
                MenuQuerySafeEducate.Visible = false;
            }
            MenuSafeEducate.Visible = MenuAddSafeEducate.Visible || MenuProcessSafeEducate.Visible ||
                                      MenuQuerySafeEducate.Visible;

            // 综合分析统计
            if (menuString.IndexOf("ArchivesReport.aspx", StringComparison.Ordinal) == -1)
            {
                MenuArchivesReport.Visible = false;
            }
            if (menuString.IndexOf("NewDataReport.aspx", StringComparison.Ordinal) == -1)
            {
                MenuNewDataReport.Visible = false;
            }
            if (menuString.IndexOf("ScoreBookReport.aspx", StringComparison.Ordinal) == -1)
            {
                MenuScoreBookReport.Visible = false;
            }
            if (menuString.IndexOf("AccidentBookReport.aspx", StringComparison.Ordinal) == -1)
            {
                MenuAccidentBookReport.Visible = false;
            }
            if (menuString.IndexOf("IllegalBookReport.aspx", StringComparison.Ordinal) == -1)
            {
                MenuIllegalBookReport.Visible = false;
            }
            if (menuString.IndexOf("SafeEducateReport.aspx", StringComparison.Ordinal) == -1)
            {
                MenuSafeEducateReport.Visible = false;
            }
            MenuReports.Visible = MenuArchivesReport.Visible || MenuNewDataReport.Visible
                                  || MenuScoreBookReport.Visible || MenuAccidentBookReport.Visible
                                  || MenuIllegalBookReport.Visible || MenuSafeEducateReport.Visible;

            // 日志查询
            if (menuString.IndexOf("LogView.aspx", StringComparison.Ordinal) == -1)
            {
                MenuLogQuery.Visible = MenuLogRoot.Visible = false;
            }

            // 用户管理
            if (menuString.IndexOf("UserView.aspx", StringComparison.Ordinal) == -1)
            {
                MenuUserManage.Visible = false;
            }
            if (menuString.IndexOf("RoleView.aspx", StringComparison.Ordinal) == -1)
            {
                MenuRoleManage.Visible = false;
            }
            MenuUserRoot.Visible = MenuUserManage.Visible || MenuRoleManage.Visible;

            // 单位管理
            if (menuString.IndexOf("UnitView.aspx", StringComparison.Ordinal) == -1)
            {
                MenuUnitManage.Visible = MenuUnitRoot.Visible = false;
            }

            // 值对象
            if (menuString.IndexOf("ValueObjectClassView.aspx", StringComparison.Ordinal) == -1)
            {
                MenuValueObjectClass.Visible = false;
            }
            if (menuString.IndexOf("ValueObjectView.aspx", StringComparison.Ordinal) == -1)
            {
                MenuValueObject.Visible = false;
            }
            MenuValueObjectRoot.Visible = MenuValueObjectClass.Visible || MenuValueObject.Visible;
        }
    }
}